package com.example.su_shi_tan_core.extentions

import android.util.Log
import com.alibaba.android.arouter.facade.Postcard
import com.example.su_shi_tan_bas_lib.base.BaseFragmentEx
import com.example.su_shi_tan_bas_lib.utils.ShUtils
import me.yokeyword.fragmentation.ISupportFragment
import me.yokeyword.fragmentation.ISupportFragment.SINGLETASK

fun Postcard.startNavigation(from: BaseFragmentEx) = apply {
    val to = navigation()
    if (to is ISupportFragment) {
        from.start(to)
    }else{
        Log.d("startNavigation", "startNavigation: $to")
        Log.d("startNavigation", "path: $path")
    }
}

fun Postcard.castBaseFragmentEx():BaseFragmentEx {
    return navigation() as BaseFragmentEx
}

fun Postcard.startNavigationSingleTask(from: BaseFragmentEx) = apply {
    val to = navigation(null)
    if (to is ISupportFragment) {
        from.start(to,SINGLETASK)
    }
}


fun Postcard.startSuperFragmentDoNotHideSelf(from: BaseFragmentEx)=apply {
    val to = navigation(null)
    if (to is BaseFragmentEx) {
        ShUtils.startFragmentDoNotHideSelf( from.superFragment,to)
    }

}


fun Postcard.startNavigationSelf(from: BaseFragmentEx) = apply {
    val to = navigation(null)
    if (to is ISupportFragment) {
        from.supportDelegate.start(to)
    }
}